<template>
  <div class="app-container">
    <el-form :model="searchForm" :inline="true">
      <el-col :span="20">
        <el-form :model="searchForm" inline @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model="searchForm.fuzzy"
              style="width: 250px"
              placeholder="仪器名称/仪器编号/仪器型号"
              clearable
              @keyup.enter.native="handleSearch"
            />
          </el-form-item>
          <el-form-item prop="startTime" label="日期选择:">
            <el-date-picker
              style="width: 250px"
              value-format="yyyy-MM-dd HH:mm:ss"
              v-model="searchForm.startTime"
              type="date"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              class="iconfont icon-chaxun1"
              @click="handleSearch"
            >
              查询</el-button
            >
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="4" class="search-right">
        <el-button type="text" @click="newPurchase">批量记录下载</el-button>
      </el-col>
    </el-form>
    <div>
      <el-table
        ref="stockTable"
        stripe
        border
        :data="tableData"
        class="table-item"
        highlight-current-row
        :header-cell-style="{ background: '#ECF3FC' }"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <template slot="empty">
          <div class="table_empty">
            <div class="empty_tips">
              <span> 暂无数据 </span>
            </div>
          </div>
        </template>

        <el-table-column
          type="selection"
          fixed="left"
          width="55"
          align="center"
        />

        <el-table-column
          type="index"
          fixed="left"
          width="55"
          align="center"
          label="序号"
        />
        <el-table-column
          prop="number"
          label="仪器编号"
          fixed="left"
          width="80"
          align="center"
        />
        <el-table-column
          prop="name"
          label="仪器名称"
          fixed="left"
          width="80"
          align="center"
        />
        <el-table-column
          prop="model"
          label="仪器型号"
          width="80"
          align="center"
        />
        <el-table-column
          prop="manufacturer"
          label="仪器品牌"
          min-width="80"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="serialNumber"
          label="出厂编号"
          min-width="100px"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="deviceType"
          label="仪器类别"
          width="80px"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.deviceType == '1'">现场采样仪器</span>
            <span v-if="scope.row.deviceType == '2'">现场检测仪器</span>
            <span v-if="scope.row.deviceType == '3'">实验室仪器</span>
            <span v-if="scope.row.deviceType == '4'">校准仪器</span>
            <span v-if="scope.row.deviceType == '5'">样品制备仪器</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="classType"
          label="检测类别"
          min-width="70px"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.classType == '1'"> 水</span>
            <span v-if="scope.row.classType == '2'">气</span>
            <span v-if="scope.row.classType == '3'">噪声</span>
            <span v-if="scope.row.classType == '4'"
              >土壤、底泥、固废、污泥和生活垃圾</span
            >
            <span v-if="scope.row.classType == '5'">样品制备</span>
            <span v-if="scope.row.classType == '6'">小型分析仪器</span>
            <span v-if="scope.row.classType == '7'">色谱仪 </span>
            <span v-if="scope.row.classType == '8'">光谱仪</span>
            <span v-if="scope.row.classType == '9'">质谱仪</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="position"
          label="放置地点"
          min-width="80px"
          align="center"
        />
        <el-table-column
          prop="department"
          label="所属部门"
          min-width="80px"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="maintainUser"
          label="维修/保养人"
          min-width="120px"
          align="center"
        />
        <el-table-column
          prop="maintainDate"
          label="维修/保养日期"
          min-width="80px"
          align="center"
        />
        <el-table-column
          prop="maintainContent"
          label="维修/保养内容"
          min-width="120px"
          align="center"
        />
        <el-table-column fixed="right" align="center" label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="text" @click="View(scope.row)"> 查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="float: right">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="searchForm.pageNumber"
        :limit.sync="searchForm.pageSize"
        @pagination="handleSearch"
      />
    </div>
    <el-dialog
      title="批量记录下载"
      :visible.sync="purchaseVisible"
      center
      @closed="dialogClose"
      top="5vh"
      width="30%"
    >
      <el-form :model="searchForm" label-width="110px">
        <el-form-item label="选择维修/保养:" prop="type">
          <el-select v-model="type" @change="typeValue" style="width: 80%">
            <el-option label="全部记录" value="3"></el-option>
            <el-option label="维修记录" value="1"></el-option>
            <el-option label="保养记录" value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="purchaseVisible = false">取消</el-button>
        <el-button type="primary" @click="handleDownload">确认</el-button>
      </div>
    </el-dialog>

    <!-- 查看 -->
    <el-dialog
      title="查看"
      :visible.sync="MyInstrumentView"
      center
      top="5vh"
      width="1400px"
    >
      <div>
        <div class="install-title">出入库申请详情信息</div>
        <el-form label-width="130px">
          <el-row :gutter="12">
            <el-col :span="8">
              <el-form-item prop="number" label="仪器编号:">
                {{ ViewForm.number }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="name" label="仪器名称:">
                {{ ViewForm.name }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="model" label="仪器型号:">
                {{ ViewForm.model }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="manufacturer" label="仪器品牌:">
                {{ ViewForm.manufacturer }}
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item prop="serialNumber" label="出厂编号:">
                {{ ViewForm.serialNumber }}
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item prop="deviceType" label="仪器类别:">
                <el-form-item>
                  <span v-if="ViewForm.deviceType == '1'">现场采样仪器</span>
                  <span v-if="ViewForm.deviceType == '2'">现场检测仪器</span>
                  <span v-if="ViewForm.deviceType == '3'">实验室仪器</span>
                  <span v-if="ViewForm.deviceType == '4'">校准仪器</span>
                  <span v-if="ViewForm.deviceType == '5'">样品制备仪器</span>
                </el-form-item>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item prop="classType" label="检测类别:">
                <span v-if="ViewForm.classType == '1'"> 水</span>
                <span v-if="ViewForm.classType == '2'">气</span>
                <span v-if="ViewForm.classType == '3'">噪声</span>
                <span v-if="ViewForm.classType == '4'"
                  >土壤、底泥、固废、污泥和生活垃圾</span
                >
                <span v-if="ViewForm.classType == '5'">样品制备</span>
                <span v-if="ViewForm.classType == '6'">小型分析仪器</span>
                <span v-if="ViewForm.classType == '7'">色谱仪 </span>
                <span v-if="ViewForm.classType == '8'">光谱仪</span>
                <span v-if="ViewForm.classType == '9'">质谱仪</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="position" label="放置地点:">
                {{ ViewForm.position }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="所属部门:" prop="department">
                {{ ViewForm.department }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="maintainUser" label="维修/保养人:">
                {{ ViewForm.maintainUser }}
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item prop="maintainDate," label="维修/保养日期:">
                {{ ViewForm.maintainDate }}
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item prop="maintainContent" label="维修/保养内容:">
                {{ ViewForm.maintainContent }}
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as addMaintenance from "@/api/Maintenance";
import Pagination from "@/components/Pagination"; // Secondary package based on el-pagination
export default {
  components: { Pagination },
  filters: {
    statusQualityFilter(status) {
      if (status === "5") {
        return "danger";
      } else if (status === "6") {
        return "success";
      } else if (
        status === "1" ||
        status === "2" ||
        status === "3" ||
        status === "4"
      ) {
        return "";
      }
    }
  },
  data() {
    return {
      rules: {},
      submitButt: false,
      modelList: [],
      purchaseForm: {
        name: "",
        model: "",
        amount: "",
        price: ""
      },
      multipleselection: "",
      type: "",
      purchaseVisible: false,
      MyInstrumentView: false,
      total: 0,
      getId: "",
      tableData: [],
      ViewForm: [],
      deptList: [],
      searchForm: {
        fuzzy: "",
        state: 1,
        pageNumber: 1,
        pageSize: 10
      },
      form: {
        region: ""
      }
    };
  },

  created() {
    this.handleSearch();
  },

  methods: {
    handleSearch() {
      addMaintenance.deviceMaintainHistory(this.searchForm).then(res => {
        if (res.code === 200 && res.result) {
          console.log(111, res);
          this.tableData = res.result.records;
          console.log(this.tableData);
          this.total = res.result.total;
        }
      });
    },
    dialogClose() {
      this.purchaseForm = {};
      this.submitButt = false;
    },
    handleCreate() {
      this.approveVisible = "create";
    },
    // 查看
    View(row) {
      console.log(row);
      this.MyInstrumentView = true;
      this.ViewForm = row;
    },
    handleSelectionChange(val) {
      console.log(val);
      this.multipleselection = val;
      var arr = [];
      for (var item of val) {
        console.log(item.id);
        arr.push(item.id);
        console.log(arr + []);
        this.Selection = arr + [];
      }
    },
    newPurchase() {
      if (this.multipleselection.length != 0) {
        this.purchaseVisible = true;
      } else {
        this.$message({
          message: "最少选择一条记录",
          type: "warning"
        });
      }
    },
    typeValue(e) {
      this.type = e;
      console.log(this.type);
    },
    /** 导出按钮操作 */
    handleDownload() {
      var url =
        "/api/excel/exportMaintainHistory?id=" +
        this.Selection +
        "&type=" +
        this.type;
      window.open(url);
      this.purchaseVisible = false
    }
  }
};
</script>

<style scoped lang="scss">
.clearfix {
  line-height: 40px;
  display: flex;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.clearfix {
  line-height: 40px;
  display: flex;
}
.install-title {
  display: flex;
  align-items: center;
  line-height: 40px;
  padding-left: 20px;
  color: rgb(15, 14, 14);
  background-color: #d7dae2;
  justify-content: flex-start;
  margin-top: 15px;
}
.delete {
  width: 10px;
  height: 10px;
  position: relative;
  top: -10px;
  cursor: pointer;
}
::v-deep .el-upload-list {
  width: 100px;
  display: flex;
  margin: 10px 10px;
}
::v-deep .el-upload-list > li {
  margin: 10px 10px;
}
::v-deep.el-upload-list__item {
  margin: 10px 10px;
}
::v-deep.el-upload-list--picture .el-upload-list__item {
  margin: 10px 10px !important;
}
.user-info-head {
  position: relative;
  display: inline-block;
  height: 120px;
}

::v-deep.avatar-upload-preview {
  width: 400px;
  border-radius: 0%;
  height: 400px;
  > img {
    transform: translateX(0);
  }
}
.user-info-head:hover:after {
  content: "+";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  color: #eee;
  background: rgba(0, 0, 0, 0.5);
  font-size: 24px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  cursor: pointer;
  line-height: 110px;
  border-radius: 50%;
}
</style>
